<?php

namespace App\Jobs;

use App\Libraries\SMS\SmsSingleSender;
use App\Libraries\Tools\Msg;
use App\Models\User\SMS;
use Illuminate\Support\Facades\Log;

class SMSJob extends Job
{


    private $mobile;
    private $text;
    private $app_id;
    private $app_key;

    /**
     * Create a new job instance.
     *
     * @param $mobile
     * @param $text
     */
    public function __construct($mobile, $text)
    {
        $this->mobile = $mobile;
        $this->text = $text . Msg::SMS_tail();
        $this->app_id = env('SMS_ID');
        $this->app_key = env('SMS_KEY');
    }

    /**
     * @return bool
     * @throws \Exception
     */
    public function handle()
    {
        $sender = new SmsSingleSender($this->app_id, $this->app_key);
        $rs = $sender->send(0, 86, $this->mobile, $this->text);
        $rs = json_decode($rs, true);
        if($rs['errmsg'] == 'OK'){
            return true;
        }
        throw new \Exception('SMS job Fail on mobile:'.$this->mobile);
    }
}
